<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@page import="java.text.SimpleDateFormat"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>超级分销登录注册表单</title>
<link rel="stylesheet" href="css/style.css" />
<body>

<div class="register-container">
	<h1>ShareLink</h1>
	
	<div class="connect">
		<p>Link the world. Share to world.</p>
	</div>
	
	<form action="get.do" method="get" id="registerForm">
		<div>
			<input type="text" name="username" class="username" placeholder="您的用户名" autocomplete="off"/>
		</div>
		<div>
			<input type="password" name="password" class="password" placeholder="输入密码" oncontextmenu="return false" onpaste="return false" />
		</div>
		<div>
			<input type="password" name="confirm_password" class="confirm_password" placeholder="再次输入密码" oncontextmenu="return false" onpaste="return false" />
		</div>
		<div>
			<input type="text" name="phone_number" class="phone_number" placeholder="输入手机号码" autocomplete="off" id="number"/>
		</div>
		<div>
			<input type="email" name="email" class="email" placeholder="输入邮箱地址" oncontextmenu="return false" onpaste="return false" />
		</div>
		
		
		
		<div>
			<input type="text" name="user" class="username" />
		</div>
		<button id="submit" type="submit">注 册</button>
	</form>
	
	
	<a href="login.jsp">
		<button type="button" class="register-tis">已经有账号？</button>
	</a>

</div>

<%
	String n = "";
	//链接数据库
	Class.forName("com.mysql.jdbc.Driver");
	Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","adminking");
	Statement stmt = conn.createStatement();
	//获取用户输入的帐号密码
	request.setCharacterEncoding("utf-8");
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String mobi = request.getParameter("phone_number");
	String eml = request.getParameter("email");
	String user = request.getParameter("user");
	//判断用户是否已经注册

	if(username != null && password != null){
		//该用户名已被注册
		ResultSet  rs = stmt.executeQuery("select name from users");
		while(rs.next()){
			n = rs.getString(1);
		}
		if(!username.equals(n)){
			stmt.execute("Insert into users(name,password,mobi,eml,img) Values('"+username+"','"+password+"','"+mobi+"','"+eml+"','"+user+"')");	
			
		}else{
			//该用户已注册
			response.sendRedirect("debug.jsp?id=1");
		}
		
	}else{
		out.print("用户名是："+username +"<br/>"+"密码是："+password);
	}
	
%>





<script src="js/jquery.min.js"></script>
<script src="js/common.js"></script>
<!--背景图片自动更换-->
<script src="js/supersized.3.2.7.min.js"></script>
<script src="js/supersized-init.js"></script>
<!--表单验证-->
<script src="js/jquery.validate.min.js?var1.14.0"></script>

</body>
</html>
    